package com.xbhog.screwdemo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Person {
    private String name;
    private String age; // 假设年龄也是字符串类型

    public Person(String name, String age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public String getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Person{name='" + name + "', age='" + age + "'}";
    }

    public static void main(String[] args) {
        List<Person> people = new ArrayList<>();
        /*people.add(new Person("Alice", "30"));
        people.add(new Person("Bob", "25"));
        people.add(new Person("Charlie", "20"));
        people.add(new Person("*", "*")); // 增加姓名和年龄都是 "*" 的对象
        people.add(new Person("David", "20"));*/
        people.add(new Person("Other", "*"));
        people.add(new Person("180", "177"));
        //people.add(new Person("180", "20"));

        // 反向排序：首先按姓名反向排序，如果姓名相同则按年龄反向排序
        List<Person> collect = people.stream().sorted(Comparator.comparing(Person::getAge)
                //.thenComparing(Person::getName)
                .reversed()).collect(Collectors.toList());
        //.thenComparing(Person::getAge, Comparator.reverseOrder())
        //).reverse();

        System.out.println(collect);
    }
}